package entity

import (
	"fmt"

	"gorm.io/gorm"
	"shqsoft.cn/pas3ui/base"
)

//ShIndiKhjldjygdr 零售定级指标导入
type ShIndiKhjldjygdr struct {
	ID   int    `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	EMID int    `gorm:"column:EMID"`
	EMNO string `gorm:"column:EMNO"`
	EMNM string `gorm:"column:EMNM"`
}

//TableName
func (ShIndiKhjldjygdr) TableName() string {
	return "SH_INDI_KHJLDJ"
}

// BeforeCreate
func (u *ShIndiKhjldjygdr) BeforeCreate(tx *gorm.DB) (err error) {
	var emid *int
	tx.Raw(`select "ID" from "T_SysUser" where "SysUserID" = ? and "SysUserName"=?`, u.EMNO, u.EMNM).Row().Scan(&emid)
	if emid == nil {
		err = fmt.Errorf("员工号%s在系统中不存在！", u.EMNO)
		return
	}
	u.EMID = *emid
	return
}

//ShIndiKhjldjygdrEF 返回结构体
func ShIndiKhjldjygdrEF() base.EntityFunc {
	return func() interface{} {
		entity := ShIndiKhjldjygdr{}
		return &entity
	}
}

//ShIndiKhjldjygdrESF 返回结构体数组
func ShIndiKhjldjygdrESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []ShIndiKhjldjygdr
		return &entities
	}
}

func init() {
	base.DaoPoolObj.Put("ShIndiKhjldjygdr", base.NewDefaultDao(ShIndiKhjldjygdrEF(), ShIndiKhjldjygdrESF(), nil, "my"))
}
